package hluck.me.srorage.bus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import hluck.me.srorage.bus.Vo.InportVo;
import hluck.me.srorage.bus.domain.BusGoods;
import hluck.me.srorage.bus.domain.BusInport;
import hluck.me.srorage.bus.domain.BusProvider;
import hluck.me.srorage.bus.service.BusGoodsService;
import hluck.me.srorage.bus.service.BusInportService;
import hluck.me.srorage.bus.service.BusProviderService;
import hluck.me.srorage.sys.common.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 老雷
 * @since 2021-02-15
 */
@RestController
@RequestMapping("/inport")
public class BusInportController {
    @Autowired
    BusInportService inportService;
    @Autowired
    BusProviderService providerService;
    @Autowired
    BusGoodsService goodsService;

    /**
     * 查询
     */
    @RequestMapping("loadAllInport")
    public DataGridView loadAllGoods(InportVo inportVo){
        Page<BusInport> page = new Page<>(inportVo.getPage(), inportVo.getLimit());
        QueryWrapper<BusInport> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(inportVo.getProviderid()!=null&&inportVo.getProviderid()!=0,"providerid",inportVo.getProviderid());
        queryWrapper.eq(inportVo.getGoodsid()!=null&&inportVo.getGoodsid()!=0,"goodsid",inportVo.getGoodsid());
        queryWrapper.ge(inportVo.getStartTime()!=null,"inporttime",inportVo.getStartTime());
        queryWrapper.le(inportVo.getEndTime()!=null,"inporttime",inportVo.getEndTime());
        this.inportService.page(page,queryWrapper);
        List<BusInport> inports = page.getRecords();
        for (BusInport inport : inports) {
            BusProvider provider = providerService.getById(inport.getProviderid());
            BusGoods goods = goodsService.getById(inport.getGoodsid());
            if (null!=provider) {
                inport.setProvidername(provider.getProvidername());
                inport.setGoodsname(goods.getGoodsname());
            }
        }
        return new DataGridView(page.getTotal(),inports);
    }
}

